package com.niuxiaofa.newlaw.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.niuxiaofa.newlaw.Bean.ExpertBean;
import com.niuxiaofa.newlaw.R;
import com.niuxiaofa.newlaw.Tools.GlideUtils;
import com.niuxiaofa.newlaw.Tools.UIUtils;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import www.linwg.org.lib.LCardView;


public class ConnoisseurAdapter extends RecyclerView.Adapter<ConnoisseurAdapter.ViewHolder> {
    public List<ExpertBean.DataDTO.ListDTO> listEntities;
    Onclick onclick;


    public ConnoisseurAdapter(List<ExpertBean.DataDTO.ListDTO> newsList, Onclick onclick) {
        this.onclick = onclick;
        this.listEntities = newsList;
    }


    @Override
    public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_connoisseur, viewGroup, false);
        ViewHolder viewHolder = new ViewHolder(view);
        return viewHolder;
    }

    String tags;

    @Override
    public void onBindViewHolder(ViewHolder viewHolder, int i) {
        tags = "";
        ExpertBean.DataDTO.ListDTO listEntity = listEntities.get(i);

        viewHolder.name.setText((String) listEntity.getUserName());

        viewHolder.address.setText(listEntity.getAddress());

        GlideUtils.loadUserImg(UIUtils.getContext(), listEntity.getHeader(), viewHolder.user_img);


        if (listEntity.getTags() != null) {
            for (int j = 0; j < listEntity.getTags().size(); j++) {
                tags = tags + listEntity.getTags().get(j);
            }
        }

        viewHolder.tags.setText("从业时间" + listEntity.getAgeLimit() + "年,擅长" + tags);

        viewHolder.lcard.setOnClickListener(e -> {
            onclick.onclick(i);
        });

        viewHolder.professional.setText(listEntity.getWorkUnit());

    }

    @Override
    public int getItemCount() {
        return listEntities.size();
    }

    public interface Onclick {

        void onclick(int c);

    }

    static class ViewHolder extends RecyclerView.ViewHolder {


        @BindView(R.id.username)
        TextView name;


        @BindView(R.id.user_img)
        ImageView user_img;

        @BindView(R.id.address)
        TextView address;

        @BindView(R.id.tags)
        TextView tags;

        @BindView(R.id.lcard)
        LCardView lcard;


        @BindView(R.id.professional)
        TextView professional;

        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
